package org.jsola.hr.constant;

import org.jsola.core.validator.IConst;
import org.jsola.json.JsonKit;

import java.util.HashMap;
import java.util.Map;

/**
 * 社保校验错误状态
 *
 * @author lyh
 */
public enum SocCheckWrongsStatus implements IConst {

    /**
     * 系统内无此人
     */
    SYS_NO_PERSON(1,"系统内无此人"),
    /**
     * 文件内无此人
     */
    EXCEL_NO_PERSON(2,"文件内无此人"),
    /**
     * 未参保
     */
    NO_SOC(3,"未参保"),
    /**
     * 社保金异常
     */
    SOC_WRONGS(4,"社保金异常"),
    /**
     * 公积金异常
     */
    PF_WRONGS(5,"公积金异常"),
    /**
     * 社保局无此人
     */
    SOC_SITE_NO_PERSON(6,"社保局无此人"),
    /**
     * 医保局无此人
     */
    ME_SITE_NO_PERSON(7,"医保局无此人"),
    /**
     * 公积金无此人
     */
    PF_SITE_NO_PERSON(8,"公积金无此人"),
    /**
     * 服务费异常
     */
    SERVICE_COST_WRONGS(9,"服务费异常"),
    /**
     * 滞纳金异常
     */
    LATE_FEES_WRONGS(10,"滞纳金异常"),
    /**
     * 员工不存在
     */
    EMP_NOT_EXIST(11,"员工不存在");

    private final Integer value;
    private final String desc;
    /**
     * 枚举值罗列，给swagger接口文档展示用
     */
    public static final String VALUES_STR = "1,2,3,4,5,6,7,8,9,10,11";

     /**
     * 缓存所有value
     */
    private static final Map<Integer, SocCheckWrongsStatus> LOOKUP = new HashMap<>();

    static {
        for (SocCheckWrongsStatus e : SocCheckWrongsStatus.values()) {
            LOOKUP.put(e.value, e);
        }
    }


    SocCheckWrongsStatus(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 根据value查找SocCheckWrongsStatus
     * @param value value
     * @return SocCheckWrongsStatus
     */
    public static SocCheckWrongsStatus find(Integer value) {
        return LOOKUP.get(value);
    }

    /**
     * 根据desc查找SocCheckWrongsStatus
     * @param desc desc
     * @return SocCheckWrongsStatus
     */
    public static SocCheckWrongsStatus findByDesc(String desc){
        for (SocCheckWrongsStatus e : SocCheckWrongsStatus.values()) {
            if(e.getDesc().equals(desc)){
                return e;
            }
        }
        return null;
    }

    /**
     * 所有枚举转json
     * @return json
     */
    public static String getAllToJson() {
        Map<String,Object> map = new HashMap<>();
        for (SocCheckWrongsStatus e : SocCheckWrongsStatus.values()) {
            map.put("value", e.value);
            map.put("desc", e.desc);
        }
        return JsonKit.toJSONString(map);
    }

    @Override
    public boolean check(Object obj) {
        Integer value = (Integer) obj;
        return find(value) != null;
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
